<template>
	<view  class="pages">
		<my-header bgCol="rgb(253, 107, 48)" :isHome="isHome"  :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">{{title}}</block>
		</my-header>
        <view class="wrap">
            <image class="header" src="../static/homegif.gif" mode="" />
            <view class="main col">
                <textarea placeholder="请输入您要去除水印的链接"  v-model="content"/>
            </view>
        </view>
       <view class="col">
            <view class="btn col bg-cyan" @click="search()">去除水印</view> 
            <video v-if="videoInfo.video_url" :src="videoInfo.video_url" :style="videoSty" @loadedmetadata="loaded"></video> 
            <!-- <video v-if="videoInfo.video_url" :src="links" :style="videoSty" @loadedmetadata="loaded"></video>  -->
            <view  v-if="videoInfo.video_url" class="btn col bg-cyan copy"  @click="copy()">复制链接</view>
            <view  v-if="videoInfo.video_url" class="btn col bg-cyan share">
                分享好友
                <button open-type="share"></button> 
            </view>
            <!-- <view  v-if="videoInfo.video_url" class="btn col bg-cyan copy"  @click="download()">保存视频</view> -->
        </view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
                videoInfo:{},
                videoSty:"",
                content:"",
                links:"",
                title:"去除水印",
                isHome:0
			}
		}, 
		onLoad(options){
            this.isHome=options.isHome||0
            this.title=options.title||"去除水印"
            this.initData()
        },
        onShow(){
            // this.initData()
             
             
        },
        onShareAppMessage(){
            let url='/videoLogo/pages/details?isHome=1&link='+this.videoInfo.token
                // uni.navigateTo({
                //     url
                // });
            return {
                title:this.videoInfo.desc,
                imageUrl:this.videoInfo.img_url,
                path:url,
                success: function (res) {}, 
            }
        },
		methods: {
            go(){
                let url='/videoLogo/pages/details?isHome=1'
                uni.navigateTo({
                    url
                });
            },
			async initData(){
                let data={...await uni.$get_copy()}.data
                let url= this.handleUrl(data)
                if (url) {
                    let res=await uni.$choose("您确认要粘贴剪切板的链接吗？")
                    if (res.code==200) {
                        this.content=url
                        console.log(url);
                    }
                } 
                
            },
            
            async getLinks(links=""){
                const res=await uni.$request({
                    links
                },"api/api/get_surl")
                this.links=res.data.url
            },
            handleUrl(str) {
                var reg = /(https?|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g;
                str = str.match(reg);
                if (str) {
                    return (str[0])
                } else {
                    return (false)
                }
	        },
			async search(){
                const res=await uni.$request({
                    url: this.handleUrl(this.content)
                },"api/api/del_logo")
                if (res.code==200) {
                    this.videoInfo=res.data
                    // this.getLinks(res.data.video_url)
                }else{
                    uni.$err(res.msg)
                }
            },
            loaded(e){
                let data=e.detail
                let w=650;
                let flg=data.width/data.height
                this.videoInfo={
                    ...this.videoInfo,
                    ...data
                }
                // this.videoSty="width:"+w+"rpx;height:"+w/flg+"rpx"
            },
            copy(){
                uni.$copy(this.videoInfo.surl)
            },
            share(){
                let link=this.content
                uni.navigateTo({
                    url: './details?link='+link
                });
            },
            download(){
                uni.downloadFile({
                    url: this.links, //仅为示例，并非真实的资源
                    success: (res) => {
                        console.log(res);
                        console.log(res.tempFilePath);
                        if (res.statusCode === 200) {
                            console.log('下载成功');
                        }
                    }
                });
            }
			
			
		}
	}
</script>

<style lang="scss">
	// @import "../../pages/house/mePage/index";
	@import "../main";
</style>